﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace XMLDOMStudy
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();

            ////1.验证DocumentElement是文档正式内容的根元素，不是dom的根
            //doc.Load("demo.xml");
            //XmlElement root = doc.DocumentElement;
            //string location= root.GetAttribute("location");
            //Console.WriteLine(location);

            doc.LoadXml("<book genre='novel' ISBN='1-861003-78' misc='sale item'>" +
               "<title>The Handmaid's Tale</title>" +
               "<price>14.95</price>" +
               "</book>");
            XmlComment comm = doc.CreateComment("i am a comment.");
            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(comm, root);

            XmlNodeList xnl = root.ChildNodes;
            for (int i = 0; i < xnl.Count; i++)
            {
                Console.WriteLine( xnl[i].NodeType.ToString()+ xnl[i].Value );
            }
            doc.Save("foo.xml");

            Console.ReadLine();
        }
    }
}
